
// 销书数据
  let xsgldata =[
  {id:'1',name:"水打开你的传",writer:"曹雪的卡片",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'2',name:"水打开了电脑传",writer:"曹地看到芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'3',name:"扩大解释传",writer:"曹看大家",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'4',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'5',name:"三国志",writer:"德邦",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'6',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'7',name:"火徐传",writer:"曹操",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'8',name:"水浒大传",writer:"曹达芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'9',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'10',name:"大苏打",writer:"曹大",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'11',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'12',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'13',name:"马儿扎哈",writer:"张乱",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'14',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'15',name:"水传",writer:"曹儿",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'16',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'17',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'18',name:"星游记",writer:"曹雪",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'19',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'20',name:"西游记",writer:"罗贯中",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'21',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'22',name:"本草纲目",writer:"李时珍",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'23',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'24',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'25',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'26',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'27',name:"莫传",writer:"更丰富",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'28',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'29',name:"红楼梦",writer:"施耐庵",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'30',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'31',name:"哒哒哒传",writer:"颗粒",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'32',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'33',name:"钢铁是怎样炼成的",writer:"高尔基",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'34',name:"水浒传",writer:"曹雪芹",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'35',name:"安徒生童话",writer:"安徒生",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
  {id:'36',name:"卖火柴的小女孩",writer:"安徒生",Presse:"新华出版社",Category:"传统文学",szsk:"华夏书库",yhdate:"2021-10-20",sjhsdate:"2021-10-20"},
]
//新增销书
function xinzengjy() {
  $('.modal-content').html(`
  <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                  aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="exampleModalLabel">新增销书</h4>
              </div>
              
                <div class="modal-body clear">
                  <p class="xsmt">
                    <span>图书编号：</span><input type="text" />
                  </p>
                  <p class="xsmt">
                    <span>图书名称：</span><input type="text"/>
                  </p>
                  <p class="xsmt">
                    <span>作者：</span><input type="text"/>
                  </p>
                  <p class="xsmt">
                    <span>出版社：</span><input type="text"/>
                  </p>
                  <div class="xsmt">
                    <p>
                      <span> 类别：</span>  <select class="form-control"  id="xsleibie">
                         <option selected hidden disabled value="" >选择类别</option>
                           <option value ="文学名著">文学名著</option>
                           <option value ="小说散文">小说散文</option>
                           <option value ="古代诗歌">古代诗歌</option>
                           <option value ="外国文学">外国文学</option>
                           <option value ="科技论文">科技论文</option>
                         </select>
                     </p>
                  </div>
                  <div class="xsmt">
                    <p><span>所在书库：</span>
                      <select class="form-control" id="xsshuku">
                          <option value ="1">001</option>
                          <option value ="2">002</option>
                          <option value ="3">003</option>
                          <option value ="4">004</option>
                          <option value ="5">005</option>
                          <option value ="6">006</option>
                          <option value ="7">007</option>
                          <option value ="8">008</option>
                          <option value ="9">009</option>
                          <option value ="10">10</option>
                        </select>
                    </p>
                  </div>
                 <div class="xsmt">
                  <p>
                    <span >入库日期：</span>  <input type="date" class="form-control kuangkuang"id="xsruku" >
                  </p>
                 </div>
                  <div class="xsmt">
                    <p>
                      <span>出库日期：</span> <input type="date" class="form-control kuangkuang"id="xschuku" >
                    </p>
                  </div>
                 
                </div>
                <div class="modal-footer fenge">
                  <button type="button" class="btn btn-default addbtn_ok" data-dismiss="modal">取消</button>
                  <button type="button" class="btn btn-primary addbtn_no" onclick="addxiaoshu()" data-dismiss="modal">确认</button>
                  </div>`)
  }
function addxiaoshu() {
  let add = new AddXsData()
  xsgldata.unshift(add)
  goPage(nowPageNum)
  // $("#exampleModal").modal('hide');
  console.log(xsgldata)
  }
  // 添加数据
function AddXsData() {
  this.id = $('.xsmt').eq(0).children().last().val()
  this.name = $('.xsmt').eq(1).children().last().val()
  this.writer = $('.xsmt').eq(2).children().last().val()
  this.Presse = $('.xsmt').eq(3).children().last().val()
  this.Category = $('#xsleibie option:selected').text()
  this.szsk = $('#xsshuku option:selected').text()
  this.yhdate = $('.xsmt').eq(6).children().children().last().val()
  this.sjhsdate =$('.xsmt').eq(7).children().children().last().val()
  }
  //编辑销书
function  change(obj){
  let objval = $(obj).parent().siblings('td')
  $('.modal-content').html(`
  <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                    aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">编辑销书</h4>
                </div>
                <div class="modal-body clear">
               
                  <div class="modal-body clear">
                    <p class="xsmt">
                      <span>图书编号：</span><input type="text" value=${objval.eq(0).text()} />
                    </p>
                    <p class="xsmt">
                      <span>图书名称：</span><input type="text" value=${objval.eq(1).text()} "/>
                    </p>
                    <p class="xsmt">
                      <span>作者：</span><input type="text" value=${objval.eq(2).text()} />
                    </p>
                    <p class="xsmt">
                      <span>出版社：</span><input type="text" value=${objval.eq(3).text()} />
                    </p>
                    <div class="xsmt">
                      <p >
                        <span> 类别：</span>  <select class="form-control" id="leibei" value=${objval.eq(4).text()}>
                           <option selected hidden disabled value="">${objval.eq(4).text()}</option>
                             <option value ="文学名著">文学名著</option>
                             <option value ="小说散文">小说散文</option>
                             <option value ="古代诗歌">古代诗歌</option>
                             <option value ="外国文学">外国文学</option>
                             <option value ="科技论文">科技论文</option>
                           </select>
                       </p>
                    </div>
                    <div class="xsmt">
                      <p><span>所在书库：</span>
                        <select class="form-control" id="bjshuku" value="${objval.eq(5).text()}" >
                          <option style="display:none" selected value="">${objval.eq(5).text()}</option>
                            <option value ="1">001</option>
                            <option value ="2">002</option>
                            <option value ="3">003</option>
                            <option value ="4">004</option>
                            <option value ="5">005</option>
                            <option value ="6">006</option>
                            <option value ="7">007</option>
                            <option value ="8">008</option>
                            <option value ="9">009</option>
                            <option value ="10">10</option>
                          </select>
                      </p>
                    </div>
                   <div class="xsmt">
                    <p>
                      <span>入库日期：</span>  <input type="date" class="form-control kuangkuang" value="${objval.eq(6).text()}" name="ruku" id="ruku" >
                    </p>
                   </div>
                    <div class="xsmt">
                      <p>
                        <span>出库日期：</span> <input type="date" class="form-control kuangkuang" value="${objval.eq(7).text()}" id="chuku" name="chuku">
                      </p>
                    </div>
                   
                  </div>
                  <div class="modal-footer fenge">
                    <button type="button" class="btn btn-default addbtn_ok" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary addbtn_no" onclick="Change()"  data-dismiss="modal">确认</button>
                  </div>
               
              </div>`)
              console.log(123);
  }
function Change(){
  for(let i=0; i<xsgldata.length; i++){
    console.log($('.xsmt').eq(0).children().last().val())
    if(xsgldata[i].id==$('.xsmt').eq(0).children().last().val()){
      console.log(0);
      xsgldata[i].id = $('.xsmt').eq(0).children().last().val()
      xsgldata[i].name = $('.xsmt').eq(1).children().last().val()
      xsgldata[i].writer = $('.xsmt').eq(2).children().last().val()
      xsgldata[i].Presse = $('.xsmt').eq(3).children().last().val()
      xsgldata[i].Category = $('#leibei option:selected').text()
      xsgldata[i].szsk = $('#bjshuku option:selected').text()
      xsgldata[i].yhdate = $('.xsmt').eq(6).children().children().last().val()
      xsgldata[i].sjhsdate =$('.xsmt').eq(7).children().children().last().val()
    }
  }
  goPage(nowPageNum)
  // console.log(goPage(nowPageNum));
  }
  //删除
function sureDel(obj) {
  let objval = $(obj).parent().siblings('td')
  let delxs = objval.first().text()
  $('.modal-content').html(`
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
          aria-hidden="true">&times;</span></button>
      <h4 class="modal-title" id="myModalLabel">删除销书</h4>
    </div>
    <div class="modal-body">
      <p>确认删除图书编号为：${delxs}&nbsp的销书管理数据吗？</p>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
      <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="shanchujy(${delxs})">确定</button>
    </div>`)
  }
  //删除销书
function shanchujy(deldata) {
  for (let i = 0; i < xsgldata.length; i++) {
    console.log(xsgldata[i].id)
    if (String(xsgldata[i].id) == deldata) {
      xsgldata.splice(i, 1)
    }
  }
  if (maxPage > Math.ceil(xsgldata.length / eachNum)) {
    prePage()
  }
  maxPage = Math.ceil(xsgldata.length / eachNum)
  showPage(maxPage)
  goPage(nowPageNum)
  }
function ischecks() {
  if ($('.checks').is(':checked')) {
    $('#piliangdel').css({
      'color': 'black'
    })
    $('#piliangdel').removeAttr('disabled')
  } else {
    $('#piliangdel').css(
      'color', 'rgb(209, 209, 209)'
    )
    $('#piliangdel').attr('disabled', "false")
  }
  }
  //批量删除确认弹框
function piliangdel() {
  $('.modal-content').html(`
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
          aria-hidden="true">&times;</span></button>
      <h4 class="modal-title" id="myModalLabel">删除借阅</h4>
    </div>
    <div class="modal-body">
      <p>确认删除选中的借阅数据吗？</p>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
      <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="plshanchu()">确定</button>
    </div>`)
  }
  //批量删除
function plshanchu(){
  $('.checks').not('#biaotou').each(function () {
    if ($(this).is(':checked')) {
      $(this).parent().parent().remove()
      let deldata = $(this).parent().next().text()
      for (let i = 0; i < xsgldata.length; i++) {
        if (xsgldata[i].id == deldata) {
          xsgldata.splice(i, 1)
        }
      }
    }
  })
  if (maxPage > Math.ceil(xsgldata.length / eachNum)) {
    prePage()
  }
  maxPage = Math.ceil(xsgldata.length / eachNum)
  showPage(maxPage)
  goPage(nowPageNum)
  // let allData = JSON.stringify(bookData)
  // sessionStorage.setItem('initialData', allData)
  }
 


